-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [amp-carousel 0.1] Fix snapping and closing race #32695
Conversation
4fc3ab5
to
c255e0e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a couple suggestions.
const impl = await ampSlideScroll.getImpl(); | ||
const devErrorSpy = env.sandbox.spy(dev(), 'error'); | ||
|
||
impl.showSlideAndTriggerAction_(NaN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be extra safe to add another unit test that also passes Infinity
or similar.
c255e0e
to
9e77182
Compare
545e810
to
bbb4999
Compare
bbb4999
to
7682f17
Compare
@@ -686,7 +686,10 @@ export class AmpSlideScroll extends BaseSlides { | |||
*/ | |||
showSlide_(newIndex) { | |||
const {noOfSlides_} = this; | |||
newIndex = dev().assertNumber(newIndex); | |||
if (isNaN(newIndex)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the stack trace, this looks like we're fixing the issue in the wrong place. We're getting a NaN
from getNextSlideIndex_
(called from updateOnScroll_
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the catch. I'll add the check there as well.
6dccb24
to
49d5468
Compare
@@ -521,6 +521,11 @@ export class AmpSlideScroll extends BaseSlides { | |||
* @return {number} a number representing the next slide index. | |||
*/ | |||
getNextSlideIndex_(currentScrollLeft) { | |||
// Addresses race where slideWidth is 0, due to being closed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what it means for the carousel to be closed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within the lightbox gallery sense, you open the carousel by clicking on the lightbox image and then close it by clicking the image in the carousel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. In that case perhaps we can update this to hidden
?
49d5468
to
c6a17c4
Compare
Closes #28050
For
amp-carousel
's in a lightbox image gallery, a race occurs when the user drags the slide slightly (but not enough to move to the next slide), and then clicks the image, which closes the carousel.Dragging the slide causes the snapping feature to kick in:
customSnap_()
which eventually callsupdateOnScroll_()
=>getNextSlideIndex_()
.At this point, we
NaN
due to0/0
, since thethis.slideWidth_
has been updated to be 0, b/c we're closing the carousel.